//
//  D1Table03UIViewController.m
//  STBasicsApp
//
//  Created by jerry on 2019/5/3.
//  Copyright © 2019 jerry. All rights reserved.
//

#import "D1Table03UIViewController.h"
#import "D1CommonModel.h"
#import "D1TABTableAnimated03ViewCell.h"

@interface D1Table03UIViewController ()<UITableViewDelegate,UITableViewDataSource> {
    NSMutableArray *dataArray;
}

@property (nonatomic, strong) UITableView *mainTV;

@end

@implementation D1Table03UIViewController

#pragma mark - LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    dataArray = [NSMutableArray array];
    [self initUI];
    // 假设3秒后，获取到数据了，代码具体位置看你项目了。
    [self performSelector:@selector(afterGetData) withObject:nil afterDelay:3.0];
}

- (void)dealloc {
    NSLog(@"==========  dealloc  ==========");
}

#pragma mark - Target Methods

/**
 获取到数据后
 */
- (void)afterGetData {
    
    // 模拟数据
    for (int i = 0; i < 20; i ++) {
        
        D1CommonModel *model = [[D1CommonModel alloc]init];
        model.gameId = [NSString stringWithFormat:@"%d",i];
        model.title = [NSString stringWithFormat:@"这里是赛事标题%d",i+1];
        model.cover = @"test.jpg";
        [dataArray addObject:model];
    }
    
    // 停止动画,并刷新数据
    [self.mainTV tab_endAnimation];
}

#pragma mark - UITableViewDataSource & UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return .1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return .1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *str = @"D1TABTableAnimated03ViewCell";
    D1TABTableAnimated03ViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    
    if (!cell) {
        NSArray *cellArray = [[NSBundle mainBundle] loadNibNamed:@"D1TABTableAnimated03ViewCell" owner:self options:nil];
        cell = [cellArray objectAtIndex:0];
    }
    [cell updateCell];
    return cell;
}

#pragma mark - Initize Methods

- (void)initData {
    dataArray = [NSMutableArray array];
}

/**
 initialize view
 初始化视图
 */
- (void)initUI {
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mainTV];
    [self.mainTV tab_startAnimation];
}

#pragma mark - Lazy Methods

- (UITableView *)mainTV {
    if (!_mainTV) {
        _mainTV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, OG_Main_Screen_Width, OG_Main_Screen_Height) style:UITableViewStyleGrouped];
        _mainTV.delegate = self;
        _mainTV.dataSource = self;
        _mainTV.rowHeight = 115;
        _mainTV.backgroundColor = [UIColor whiteColor];
        _mainTV.estimatedSectionFooterHeight = 0;
        _mainTV.estimatedSectionHeaderHeight = 0;
        _mainTV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainTV.tabAnimated = [TABTableAnimated animatedWithCellClass:[D1TABTableAnimated03ViewCell class] cellHeight:115];
        _mainTV.tabAnimated.cancelGlobalCornerRadius = YES;
        _mainTV.tabAnimated.animatedHeight = 14.f;
    }
    return _mainTV;
}

@end
